<?php

class Administrators extends Zend_Db_Table_Abstract
{
    public function get_personal_info( $id )
    {
    	$results = array();
		
		if(empty($id))
		{
			$results['status'] = 'FAILED_BAD_PARAM';
			return $results;
		}
		
		try
		{
	        $info = $this->fetchRow("user_id=$id");		
			$results['status'] = 'SUCCEEDED';
			$results['rows'] = array( $info->toArray() );
		}
		catch(Exception $e)
		{
			$results['status'] = 'FAILED';
			$results['rows'] = array();
		}
		
        return $results;
    }

    public function get_profile_info( $id )
    {
    	$results = array();
		
		if(empty($id))
		{
			$results['status'] = 'FAILED_BAD_PARAM';
			return $results;
		}
		
		try
		{
	        $info = $this->fetchRow("id=$id");		
			$results['status'] = 'SUCCEEDED';
			$results['rows'] = array( $info->toArray() );
		}
		catch(Exception $e)
		{
			$results['status'] = 'FAILED';
			$results['rows'] = array();
		}
		
        return $results;
    }

    public function updateAdministratorProfile( &$profile, $VAS_admin_id )
    {
		$results = array();
		
		if(!isset($profile) || empty($VAS_admin_id))
		{
			$results['status'] = 'FAILED_BAD_PARAM';
			return $results;
		}   
		
		
		$profileToEdit = array();
		
		$profileToEdit["fname"] = $profile["fname"];
		$profileToEdit["mname"] = $profile["mname"];
		$profileToEdit["lname"] = $profile["lname"];
		$profileToEdit["address"] = $profile["address"];
		$profileToEdit["city"] = $profile["city"];
		$profileToEdit["state"] = $profile["state"];
		$profileToEdit["zip"] = $profile["zip"];
		$profileToEdit["phone"] = $profile["phone"];
		$profileToEdit["email"] = $profile["email"];
		
		try
		{
			$r = $this->update( $profileToEdit, "id=$VAS_admin_id");
			if($r)
			{
				$results['status'] = "SUCCEEDED";
				$results['rows_affected'] = 1;
			}	
		}
		catch(Exception $e)
		{
			$results['status'] = "FAILED";
			$results['rows_affected'] = 0;
		}
		
        return $results;
    }

    public function addAdministrator( &$profile )
    {
		$results = array();

		if(!isset($profile))
		{
			$results['status'] = 'FAILED_BAD_PARAM';
			return $results;
		}   		
		
		$profileToAdd = array();
		
		$profileToAdd["fname"] = $profile["fname"];
		$profileToAdd["mname"] = $profile["mname"];
		$profileToAdd["lname"] = $profile["lname"];
		$profileToAdd["address"] = $profile["address"];
		$profileToAdd["city"] = $profile["city"];
		$profileToAdd["state"] = $profile["state"];
		$profileToAdd["zip"] = $profile["zip"];
		$profileToAdd["phone"] = $profile["phone"];
		$profileToAdd["email"] = $profile["email"];
		
		try
		{
			$r = $this->insert( $profileToAdd );	
			if($r)
			{
				$results['status'] = "SUCCEEDED";
				$results['rows_affected'] = 1;
			}
			else
			{
				$results['status'] = "FAILED";
				$results['rows_affected'] = 2;
			}
		}
		catch(Exception $e)
		{
				$results['status'] = "FAILED";
				$results['rows_affected'] = 0;
		}
		
        return $results;
    }
	
	public function getAdministrators( )
	{		
		$results = array();
		
		try
		{
			$r = $this->fetchAll();
			$results['status'] = 'SUCCEEDED';
			$results['rows'] = $r->toArray();	
		}
		catch(Exception $e)
		{
			$results['status'] = 'FAILED';
			$results['rows'] = array();	
		}
		
        return $results;
	}
	
	public function getRegionalVPs()
	{		
		$results = array();
        return $results;
	}
	
	public function getRegionalAreaManagers( $region )
	{		
		$results = array();

		if(!isset($profile))
		{
			$results['status'] = 'FAILED_BAD_PARAM';
			return $results;
		}
		
        return $results;
	}
}

?>
